<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>到货验收---开箱检验</title>

    <!--公用样式-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/comment.css"/>
    <!--页面样式-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/style.css"/>
    <!--Layui-->
    <link rel="stylesheet" href="${re.contextPath}/plugin/layui/css/layui.css" media="all"/>
    <!--extended-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/extended.css"/>
    <!--公用样式JS-->
    <script type="text/javascript" src="${re.contextPath}/plugin/jquery/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="${re.contextPath}/plugin/common/js/comment.js"></script>
    <script type="text/javascript" charset="utf-8" src="${re.contextPath}/plugin/common/js/jquery.boot.js"></script>
    <script type="text/javascript" src="${re.contextPath}/plugin/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${re.contextPath}/plugin/tools/tool.js"></script>
    <script type="text/javascript" src="${re.contextPath}/pageoffice.js" id="po_js_main"></script>
</head>
<style type="text/css">
    .main {
        float: left;
        margin-left: 8px;
    }
</style>

<body>
<!--容器-->
<div>
    <div class="downModule whitebg">
        <ul class="mt30 mb30">
            <li>
                <div class="clearfix">
                    <div class="downModuleTip clearfix fl">
                        <img src="${re.contextPath}/plugin/common/images/15@2x.png" alt="" class="fl">
                        <span class="fl ml10 mt10 milefile" data-filetype="040">设备开箱检验报告</span>
                        <input type="hidden" name="fileid" id="fileid" value="${filedto.id}">
                        <input type="hidden" name="id" id="id" value="${filedto.projectId}">
                        <input type="hidden" name="fbId" id="fbId" value="${fbId}">

                        <input type="hidden" name="spmId" id="spmId" value="${filedto.spmId}">
                        <input type="hidden" name="fbcode" id="fbcode" value="${contract.code}">
                        <input type="hidden" name="stageId" id="stageId" value="${filedto.stageId}">

                    </div>
                    <div class="downModuleBtn clearfix fr">
                        <label>
                            <img src="${re.contextPath}/plugin/common/images/18@2x.png" alt="" class="fl "
                                 lay-data="{type: '040',value:'21'}">
                            <button type="button" style="display: none;" lay-data="{type: '040',value:'21'}"
                                    class="img-upload whitebutton ft12 blue">点击上传
                            </button>
                        </label>
                        <img src="${re.contextPath}/plugin/common/images/57@2x.png" alt="" class="fl"
                             onclick="addForm(this)">
                        <img src="${re.contextPath}/plugin/common/images/19@2x.png" alt="" class="fl"
                             onclick="clickDelete(this)">
                    </div>
                </div>
                <ul class="clearfix" id="ulfile">
                    <#list list_file as vfile>
                        <div>
                            <div>
                                <li class="clearfix">
                                    <input type="checkbox" class="fl" value="${vfile.id}" title="jlzb">
                                    <span class="fl ml10 mt10">${vfile.fileName}</span>
                                    <@shiro.hasPermission name="file:thrstamp">
                                        <button type="button" class="fr ml20 mt15 bgnone filelist-btn "
                                                onclick="jfsqclick(this)">监发三签
                                        </button>
                                    </@shiro.hasPermission>
<#--                                    <@shiro.hasPermission name="file:upseal">-->
<#--                                               <button type="button" class="fr mt15 bgnone ml20 upseal tabsealup0">上传签章</button>-->
<#--                                     </@shiro.hasPermission>-->
                                    <button type="button" class="fr ml20 mt15 bgnone filelist-btn tabup99">上传附件</button>
                                    <@shiro.hasPermission name="file:export">
                                        <button type="button" class="fr ml20 mt15 bgnone filelist-btn"
                                                onclick="exportFile(this)">导出
                                        </button>
                                    </@shiro.hasPermission>
                                    <@shiro.hasPermission name="file:view">
                                        <button type="button" class="fr mt15 bgnone ml20 filelist-btn btn_vew"
                                                onclick="viewFile(this)">查看
                                        </button>
                                    </@shiro.hasPermission>
                                </li>
                            </div>
                            <div>
                                <table id="table${vfile.id}" style="height: 300px;" class="layui-hide"
                                       lay-filter="table${vfile.id}"></table>
                            </div>
                        </div>

                    </#list>
                </ul>
            </li>
        </ul>
    </div>
</div>
<script type="text/javascript" src="${re.contextPath}/plugin/system/supervisor/guide.js"></script>
<script type="text/javascript" src="${re.contextPath}/plugin/system/supervisor/projectManager.js"></script>
<script>
  var layer, form, laydate, upload, uploadListIns, element, tableIns, table;
    $(function () {
        layui.use(['form', 'laydate', 'layer', 'upload', 'element', 'table'], function () {
            laydate = layui.laydate;
            form = layui.form;
            upload = layui.upload;
            element = layui.element;
            table = layui.table;
            var datajson = {
                "id": "${filedto.projectId}",
                "parentId": "${filedto.id}",
                "fbId": "${fbId}",
                "type": "040",
                "uploadType": "21"
            }
            var url = '/supervisor/projectManager/addFile';
            upload.render({
                elem: ".tabup99",
                url: url,
                multiple: true,
                accept: 'file',
                auto: true,
                data: datajson,
                before: function (obj) {
                    var item = this.item;
                    // 获取文件id
                    datajson.parentId = $(item).parent().find("[type=checkbox]").attr("value");
                },
                done: function (res, index, upload) {
                    var flag = res.flag;
                    if (flag) {
                        var url = res.data;
                        var tablelist = "table" + datajson.parentId;
                        innitTable(datajson, tablelist);
                    } else {
                        layer.msg("文件上传失败", {icon: 2})
                    }
                },
                error: function (index, upload) {
                    layer.msg("文件上传失败", {icon: 2})
                }
            });
            //初始化列表
            $("#ulfile").find("li").each(function (i, v) {
                var v_id = $(v).find("[type=checkbox]").attr("value");
                datajson.parentId = v_id;
                var tablelist = "table" + v_id;
                innitTable(datajson, tablelist);
            });

            var parentid = document.getElementById('fileid').value;

            var  datajsonkxjy = {
                "id": "${filedto.projectId}", //项目id
                "spmId": "${filedto.spmId}", //里程id
                "type": '040', //文件类型
                "fs_status": '21', //传的时候 对应的状态p'r
                "stageId": "${filedto.stageId}", // 阶段id
                "fbId": "${fbId}",
                "parentId": parentid
            }

            /**
             * 开箱检验上传
             */
            upload.render({
                elem: ".img-upload",
                url: url,
                multiple: true,
                accept: 'file',
                auto: true,
                data: datajsonkxjy,
                before: function (obj) {
                    var item = this.item;
                    // 获取文件id
                    // datajsonkxjy.parentId = $(item).parent().find("[type=checkbox]").attr("value");
                    // console.log("看看参数,",datajsonkxjy)
                },
                done: function (res, index, upload) {
                    var flag = res.flag;
                    if (flag) {
                        var url = res.data;
                        window.location.reload();
                        // console.log("看看url",url)
                        // var tablelist = "table" + datajsonkxjy.parentId;
                        // innitTable(datajsonkxjy, tablelist);
                    } else {
                        layer.msg("文件上传失败", {icon: 2})
                    }
                },
                error: function (index, upload) {
                    layer.msg("文件上传失败", {icon: 2})
                }
            });
        });
    });

    function innitTable(jsonimagedata, tablelist) {
        var flag = true;
        var flagoper = false;
        var v_bfb = "50%";
        var oper = "30%";
        table = layui.table;
        //方法级渲染
        tableIns = table.render({
            id: tablelist,
            elem: '#' + tablelist,
            url: '/supervisor/projectManager/showFileList',
            where: jsonimagedata,//如果无需传递额外参数，可不加该参
            cols: [[
                {
                    title: '序号', width: '65', templet: function (res) {
                        return res.LAY_INDEX;
                    }
                },
                {field: 'url', title: 'url', width: '30%', hide: true, sort: true},
                {
                    field: 'fileName', title: '文件名称', width: v_bfb, sort: true, align: 'left',
                    templet: function (d) {
                        return '' + d.fileName + '<img  style="width: 30px;height: 30px;float:right;" src="/plugin/common/images/big.png" onclick="_prom_page.events.viewImage(\'' + d.id + '\',\'' + d.url + '\')">'
                    }
                },
                {
                    field: 'createDate',
                    title: '上传时间',
                    align: 'left',
                    width: '190',
                    sort: true,
                    templet: '<div>{{ _prom_page.events.formatdate(d.createDate,"yyyy-MM-dd hh:mm:ss")}}</div>'
                },
                {
                    field: 'createDate', title: '操作', width: oper, sort: true, hide: flagoper, align: 'left',
                    templet: function (d) {
                        return '<img  style="width: 30px;height: 30px;float:left;" src="/plugin/common/images/del.png" onclick="deletefj(\'' + d.id + '\',\'' + tablelist + '\')">'
                    }
                },
            ]],
            done: function (res, currentCount) {

            }
        });


    }

    function deletefj(a,table) {
            var ids = [];
            ids.push(a);
            var ids = ids.join(',');
            layer.confirm('确定删除文件吗？', function (index) {
                layerAjax('/supervisor/projectManager/deleteFile', {"ids": ids}, '', function (d) {
                    if(d.flag){
                        layer.msg("删除成功！");
                        layui.table.reload(table,{});
                    }else{
                        layer.msg(d.msg, {icon: 2});
                    }
                });
            });
    }

    function viewFile(a) {
        var that = $(a);
        var _fid = that.parent().find('input[type=checkbox]').attr('value');
        if (_fid) {
            POBrowser.openWindowModeless('/sys/office/openword?ft=3&fid=' + _fid, 'width=1200px;height=800px;', '{}')
        } else {
            layer.msg('未获取到文件ID。', {icon: 2});
        }
    }

    // 开箱检验
    function kxjy(object) {
        var checkbox = $(object).parent().find("[type=checkbox]");
        //获取文件id
        var wjid = $(checkbox).attr("value");
        var laydata = eval('(' + $(object).parent().find(".img-upload").attr("lay-data") + ')');
        var type = laydata.type;
        var fbcode = laydata.code;
        if (fbcode == undefined) {
            fbcode = "";
        }
        var title = laydata.title;
        var w = "";
        var h = "";
        if (w == null || w == '') {
            w = ($(window).width());
        }
        ;
        if (h == null || h == '') {
            h = ($(window).height() - 50);
        }
        var url = "/supervisor/projectManager/addForm?type=" + type + "&id=" + jsondata.id + "&spmId=" + jsondata.spmId + "&stageId=" + jsondata.stageId + "&fbcode=" + fbcode;
        layer.open({
            id: 'form-add',
            type: 2,
            area: [w + 'px', h + 'px'],
            fix: false,
            maxmin: true,
            shadeClose: false,
            shade: 0.4,
            title: title,
            content: url
        });
    }

    function clickDelete(object) {
        var checkbox = $(object).parent().parent().next().find("input:checked");
        if (checkbox.length == 0) {
            layer.msg("请选择文件", {icon: 2});
            return;
        }
        var ids = [];
        checkbox.each(function (i, v) {
            var _a = $(v).attr("value");
            ids.push(_a);
        });
        var ids = ids.join(',');
        layer.confirm('确定删除文件吗？', function (index) {
            layerAjax("deleteFile",{"ids": ids},'',function (d) {
                if (d.flag) {
                    checkbox.each(function (i, v) {
                        if ($(v).parent().parent("div").length > 0) {
                            $(v).parent().parent().nextAll().remove();
                        }
                        $(v).parent().remove();
                    });
                    layer.msg("删除成功！");
                } else {
                    layer.msg(d.msg, {icon: 2});
                }
            })
        });

    }


    function exportFile(object) {
        var input = $(object).parent().find("input");
        var id = $(input).attr("value");
        window.open("/supervisor/projectManager/exportFile?id=" + id);
    }

    function addForm(object) {
        var id = $("#id").val();// 项目id
        var spmId = $("#spmId").val();// spmId
        var stageId = $("#stageId").val();// stageId
        var type = "040";// 文件类型
        var fbcode = $("#fbcode").val();//分包编号
        var fileid = $("#fileid").val();//文件ID
        var title = "";
        var w, h;
        if (!w) {
            w = ($(window).width()) - 300;
        }
        if (!h) {
            h = ($(window).height() - 55);
        }
        var url = "/supervisor/projectManager/addForm?type=" + type + "&id=" + id + "&stageId=" + stageId + "&spmId=" + spmId + "&fbCode=" + fbcode + "&fileId=" + fileid;
        layer.open({
            id: 'form-add',
            type: 2,
            area: [w + 'px', h + 'px'],
            fix: false,
            maxmin: true,
            shadeClose: false,
            shade: 0.4,
            title: title,
            content: url,
            success: function (layero) {
                layero.find('.layui-layer-min').remove();
            },
            end: function () {
                reload();//刷新列表页面
            }
        });
    }

    function jfsqclick(object) {
        // 监发三签
        var that = $(object);
        // 文件id
        var fileId = that.parent().find('input[type=checkbox]').attr('value');
        // 项目id
        var projectId = '${filedto.projectId}';
        var spanfile = that.parent().find("span").html()
        var fileName = spanfile.substring(0, spanfile.indexOf('.'));
        var jsonsp = {
            type: "004",//监发三签
            projectId: projectId,
            fileId: fileId,
            fileName: fileName
        }
        var title = "";
        var url = "/supervisor/lcManager/lcselectJsr?type=004&projectId=" + projectId + "&fileId=" + fileId + "&fileName=" + fileName;
        layer.open({
            id: 'form-add',
            type: 2,
            area: ['600px', '400px'],
            fix: false,
            maxmin: true,
            shadeClose: false,
            shade: 0.4,
            title: title,
            content: url
        });

    }

    // form 关闭之后回调
    function reload() {
        window.location.reload()
    }

</script>
</body>

</html>
